package com.yampi.mahjong;

import android.app.Fragment;
import android.os.Bundle;
import com.unity3d.player.*;
import com.yampi.mahjong.aliapi.Alipay;
import com.yampi.mahjong.wxapi.WXApi;

/**
 * Created by hongfeng.wu on 2017/10/10.
 */

public class YampiSdk extends Fragment {

    private static final String TAG = "YampiPlugin";
    private static YampiSdk Instance = null;
    private String gameObjectName;

    private Alipay alipay;

    public WXApi wxApi;

    public YampiSdk()
    {
        alipay = new Alipay();
    }

    public static YampiSdk GetInstance(String gameObjectName)
    {
        if(Instance == null)
        {
            Instance = new YampiSdk();
            Instance.gameObjectName = gameObjectName;
            UnityPlayer.currentActivity.getFragmentManager().beginTransaction().add(Instance, TAG).commit();
        }
        return Instance;
    }

    public static YampiSdk GetInstance()
    {
        if(Instance == null)
        {
            Instance = new YampiSdk();
            UnityPlayer.currentActivity.getFragmentManager().beginTransaction().add(Instance, TAG).commit();
        }
        return Instance;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRetainInstance(true);
    }

    public void Pay(int type, String appId, String totalAmount, String body, String rsa2_private, String rsa_private)
    {
        switch (type)
        {
            case 0:
                alipay.Pay(appId, totalAmount, body, rsa2_private, rsa_private);
                break;
        }
    }
}
